/*#include <iostream>
#include <vector>
using namespace std;
int n,m;
vector<int> path;
void dfs(int pos,int start)
{
    if(pos>m)
    {
        for(auto x:path)cout<<x<<" " ;
        cout<<endl;
        return;
    }
    for(int i=start;i<=n;i++)
    {
        path.push_back(i);
        dfs(pos+1,i+1);
        path.pop_back();
    }
}
int main()
{
    cin>>n>>m;
    dfs(1,1);
    return 0;
}*/
#include <iostream>
#include <vector>
using namespace std;
const int N=15;
bool col[N],st1[N],st2[N];
int ret=0;
int n;
vector<int> path;
void dfs(int pos)
{
	if(pos>n)
	{
		ret++;
		if(ret<=3)
		{
			for(auto x : path) cout<<x<<" ";
			cout<<endl;
			return;
		}
	}
	for(int y=1;y<=n;y++)
	{
		if(col[y]||st1[y-pos+n]||st2[y+pos])continue;
		path.push_back(y);
		col[y]=true;st1[y-pos+n]=true;st2[y+pos]=true;
		dfs(pos+1);
		path.pop_back();
		col[y]=false;st1[y-pos+n]=false;st2[y+pos]=false;
	}
}
int main()
{
	cin>>n;
	dfs(1);
	cout<<ret<<endl;
	return 0;
}
